package com.zzw.common;


import com.zzw.utils.JsonHelper;

/**
 * @author Administrator
 */
public class ApiCommonResponse<E> {
    public static final String OK = "Ok";
    public static final String SYSTEM_EXCEPTION = "SystemException";
    public static final String SYSTEM_ERROR = "SystemError";
    private final String status;
    private final String message;
    private final String sn;
    private E obj;

    public String getStatus() {
        return status;
    }

    public String getMessage() {
        return message;
    }

    public String getSn() {
        return sn;
    }

    public E getObj() {
        return obj;
    }

    public void setObj(E obj) {
        this.obj = obj;
    }

    public ApiCommonResponse(String sn) {
        this.sn = sn;
        this.status = OK;
        this.message = "success";
    }

    public ApiCommonResponse(String sn, String status, String message) {
        this.sn = sn;
        this.status = status;
        this.message = message;
    }

    public ApiCommonResponse(String sn, E obj) {
        this.status = OK;
        this.message = "success";
        this.obj = obj;
        this.sn = sn;
    }

    public static <E> ApiCommonResponse<E> of(String sn, String status, String message) {
        return new ApiCommonResponse<>(sn, status, message);
    }

    public static <E> ApiCommonResponse<E> of(String sn, E obj) {
        return new ApiCommonResponse<>(sn, obj);
    }

    public static <E> ApiCommonResponse<E> of(String sn) {
        return new ApiCommonResponse<>(sn);
    }

    @Override
    public String toString() {
        return JsonHelper.toJson(this);
    }
}
